#!/usr/bin/env python
"""
Create a simple joystick dialog box

Copyright (c) 2008 Rune M. Friborg, runef@diku.dk.
See LICENSE.txt for licensing details (GPLv2).
"""

import wx
import sys

if len(sys.argv) != 3:
    sys.exit(0)

title = sys.argv[1]
msg = sys.argv[2]

BUTTON_UP = 1000
BUTTON_DOWN = 1001
BUTTON_LEFT = 1002
BUTTON_RIGHT = 1003
BUTTON_PLUS = 1004
BUTTON_MINUS = 1005

class JoystickDialog(wx.Panel):
    def OnSetFocus(self, evt):
        evt.Skip()

    def OnKillFocus(self, evt):
        evt.Skip()

    def __init__(self, parent, id, title, msg):
        
        self.dialog = wx.Dialog(parent, -1, title, style = wx.DEFAULT_FRAME_STYLE | wx.WANTS_CHARS)
        wx.Panel.__init__(self, self.dialog, -1)

        wx.StaticText(self, -1, msg, (8, 10))

        self.btnPlus = wx.Button(self, BUTTON_PLUS, "Zoom In", (25,40))
        self.Bind(wx.EVT_BUTTON, self.EvtPlusButton, self.btnPlus)

        self.btnMinus = wx.Button(self, BUTTON_MINUS, "Zoom Out", (105,40))
        self.Bind(wx.EVT_BUTTON, self.EvtMinusButton, self.btnMinus)

        self.btnUp = wx.Button(self, BUTTON_UP, "Up", (70,75))
        self.Bind(wx.EVT_BUTTON, self.EvtUpButton, self.btnUp)

        self.btnDown = wx.Button(self, BUTTON_DOWN, "Down", (70,125))
        self.Bind(wx.EVT_BUTTON, self.EvtDownButton, self.btnDown)

        self.btnLeft = wx.Button(self, BUTTON_LEFT, "Left", (20,100))
        self.Bind(wx.EVT_BUTTON, self.EvtLeftButton, self.btnLeft)

        self.btnRight = wx.Button(self, BUTTON_RIGHT, "Right", (110,100))
        self.Bind(wx.EVT_BUTTON, self.EvtRightButton, self.btnRight)

        # Fix: makes windows redraw the dialog
        self.dialog.SetClientSize(wx.Size(210,160))
        
    def EvtUpButton(self, evt):
        sys.stdout.write('UP\n')
        sys.stdout.flush()

    def EvtDownButton(self, evt):
        sys.stdout.write('DOWN\n')
        sys.stdout.flush()

    def EvtLeftButton(self, evt):
        sys.stdout.write('LEFT\n')
        sys.stdout.flush()

    def EvtRightButton(self, evt):
        sys.stdout.write('RIGHT\n')
        sys.stdout.flush()

    def EvtPlusButton(self, evt):
        sys.stdout.write('+\n')
        sys.stdout.flush()

    def EvtMinusButton(self, evt):
        sys.stdout.write('-\n')
        sys.stdout.flush()
    
    def ShowModal(self):
        return self.dialog.ShowModal()
        
    def Destroy(self):
        self.dialog.Destroy()


app = wx.PySimpleApp()      
dlg = JoystickDialog(None, -1, title, msg)

dlg.ShowModal()
dlg.Destroy()
